﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace LanAnh
{
    public class MyServerConfig
    {
        private static String _sServerAdd = null;
        private static String _fileName = null;

        public static String Filename
        {
            get { return MyServerConfig._fileName; }
            set { MyServerConfig._fileName = value; }
        }

        public static String SServerAdd
        {
            get { return MyServerConfig._sServerAdd; }
            set { MyServerConfig._sServerAdd = value; }
        }
        private static XmlDocument xmlDocument = null;
        private static String sServerAdd = "localhost";

        public static void InitServer(String filename)
        {
            Filename = filename;
            try
            {
                xmlDocument = new XmlDocument();
                xmlDocument.Load(Filename);
                XmlNode eleServerAdd = xmlDocument.GetElementsByTagName("SERVERNAME")[0];
                SServerAdd = eleServerAdd.InnerText;

            }
            catch //my server
            {

            }
        }
        public static void SaveServerConfig()
        {
            Filename = "DataConfig.xml";
            if (xmlDocument == null)
                xmlDocument = new XmlDocument();
            xmlDocument.Load(Filename);
            XmlNode eleServerAdd = xmlDocument.GetElementsByTagName("SERVERNAME")[0];
            if (SServerAdd == "")
                return;
            eleServerAdd.InnerText = SServerAdd;
            xmlDocument.Save(Filename);
        }

    }
}
